<!DOCTYPE html>
<html>
    <head>
        <title>
            登陆
        </title>
        <link href="/static/base.css" rel="stylesheet" type="text/css">
            <script src="/static/jquery3.4.js">
            </script>
            <script src="/static/jqueryCookie1.4.1.js">
            </script>
            <script src="/static/lib.js">
            </script>
        </link>
    </head>
    <style type="text/css">
        h1{
        text-align: center;
    }
    .content{
        text-align: center;
        width:100%;
        /*height:20rem;*/
        border: 0px solid grey;
    }
    .content p{
        text-align: center;
        margin-top: 5rem;
    }
    </style>
    <body>
        <h1>
            登陆
        </h1>
        <div class="content">
            <p>
                <input name="user" type="text" placeholder="  账号..." class="input">
                </input>
            </p>
            <p>
                <input name="pwd" type="password" placeholder="  密码..." class="input">
                </input>
            </p>
            <p>
                <input type="button" value="登陆">
                </input>
            </p>
        </div>
    </body>
</html>
<script type="text/javascript">
    $(function(){
        canvas();
        $('[type="button"]').on('click', function() {
            var name = $('[name="user"]').val();
            var pwd = $('[name="pwd"]').val();
            $.ajax({
                url:'/login',
                data:{
                    name:name,
                    pwd:pwd,
                },
                type:'post',
                dataType:'json',
                success:function(res){
                    console.log(res)
                    if (res.code == 200) {
                        localStorage.setItem("token", res.data.token);
                        location.href = "/";
                    } else {
                        alert(res.msg);
                    }
                },
                error:function(err){
                    console.log(err);
                }
            });
        });
        $(document).on('keydown',function(event){
            if(event.keyCode == '13'){
                $('[type="button"]').click();
            }
        });
    })
</script>